package com.zeroone.star.publish.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zeroone.star.publish.entity.Contact;
import com.zeroone.star.publish.mapper.ContactMapper;
import com.zeroone.star.publish.mapper.UserMapper;
import com.zeroone.star.publish.service.IContactService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.mapstruct.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author car
 * @since 2024-03-02
 */

@Mapper(componentModel = "spring")
interface MyContactMapper {

}

@Service
public class ContactServiceImpl extends ServiceImpl<ContactMapper, Contact> implements IContactService {


    @Autowired
    private ContactMapper contactMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Contact> selectContactById(Integer userId) {
        QueryWrapper<Contact> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        return contactMapper.selectList(wrapper);
    }

    @Override
    public String addContact(Contact contact) {
        return contactMapper.insert(contact) == 1 ? "增加成功" : "增加失败";
    }
}
